import { useReactive } from "ahooks";
import { useModel } from "umi";
import { useEffect } from "react";
import compress from "gql-compress";

const useAllCategories = () => {
    const { graphqlFetch } = useModel("global");

    const state = useReactive({
        categoriesLoading: false,
        categories: [],
    });

    // 加载所有部门信息, 用树的数据格式
    const loadAllcategories = async (oiType) => {
        state.categoriesLoading = true;
        // let res = await graphqlFetch({
        //     query,
        //     variables: {},
        // });
        // let categories = res?.a?.nodes || [];
        let categories = [
            { ccUuid: 1, ccPaid: null, ccName: "一级品类" },
            { ccUuid: 2, ccPaid: 1, ccName: "二级品类" },
            { ccUuid: 3, ccPaid: null, ccName: "一级品类2" },
        ]
        state.categories = categories;
        state.categoriesLoading = false;
        return categories;
    };

    useEffect(() => {
        loadAllcategories();
    }, []);

    return { ...state, loadAllcategories };
};

const query = compress(``);

export default useAllCategories;
